home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / jpl_c.zip / SINH.C < prev    next >
Text File  |  1986-05-18  |  2KB  |  83 lines

  1. /* 1.0  04-27-84 */
  2. /************************************************************************
  3.  *            Robert C. Tausworthe                *
  4.  *            Jet Propulsion Laboratory            *
  5.  *            Pasadena, CA 91009        1984        *
  6.  ************************************************************************
  7.  *    Programmmed using the algorithms given in:
  8.  *
  9.  *    Coty, William J., Jr., and Waite, William, SOFTWARE MANUAL FOR
  10.  *    THE ELEMENTARY FUNCTIONS, Prentice-Hall Series in Computational
  11.  *    Mathematics, Prentice-Hall, Inc., Inglewood Cliffs, NJ, 1980,
  12.  *    pp. 217-238.
  13.  *
  14.  *----------------------------------------------------------------------*/
  15.  
  16. #include "defs.h"
  17. #include "stdtyp.h"
  18. #include "errno.h"
  19. #include "mathtyp.h"
  20. #include "mathcons.h"
  21.  
  22. /*----------------------------------------------------------------------*/
  23.  
  24. #define P0     -0.35181283430177117881e+6
  25. #define P1     -0.11563521196851768270e+5
  26. #define P2     -0.16375798202630751372e+3
  27. #define P3     -0.78966127417357099479e+0
  28. #define P(z)     (((P3*z P2)*z P1)*z P0)
  29.  
  30. #define Q0     -0.21108770058106271242e+7
  31. #define Q1     +0.36162723109421836460e+5
  32. #define Q2     -0.27773523119650701667e+3
  33. #define Q3    +1.0
  34. #define Q(z)     (((z Q2)*z Q1)*z Q0)
  35.  
  36. #define LNv    0.69316101074218750000
  37. #define Vm2    0.24999308500451499336
  38. #define Vov2m1    0.13830277879601902638e-4
  39.  
  40. /*\p*********************************************************************/
  41.     double
  42. sinh(x)            /* return hyperbolic sine of x            */
  43.  
  44. /*----------------------------------------------------------------------*/
  45. double x;
  46. {
  47.     double y, w, z;
  48.     FAST int sgn;
  49.     
  50.     if (x < 0.0)
  51.     {    y = -x;
  52.         sgn = 1;
  53.     }
  54.     else
  55.     {    y = x;
  56.         sgn = 0;
  57.     }
  58.     if (y > 1.0)
  59.     {    w = y - LNv;
  60.         if (w > LOGINFINITY)
  61.         {    errno = ERANGE;
  62.             z = INFINITY;
  63.         }
  64.         else
  65.         {    z = exp(w);
  66.             if (w < PRECISION)
  67.                 z -= Vm2 / z;
  68.             z += Vov2m1 * z;
  69.         }
  70.         if (sgn)
  71.             z = -z;
  72.     }
  73.     else if (y < FADEOUT)
  74.         z = x;
  75.     else
  76.     {    z = x * x;
  77.         z = x + x * z *
  78.             P(z)
  79.             /Q(z);
  80.     }
  81.     return z;
  82. }
  83.